var User = function() {
	var userInit = function(){
		$('#datatable-responsive').DataTable({
              "processing": true,
              "serverSide": true,
              "searchDelay": 1000,
              ordering:  false,
              "search":{
                  regex:true,
              },
              "ajax": {
                  // ajax请求地址
                'url' : '/wechatapi/wechatuser/ajaxIndex',
            },
            // 注意: 这里列的数量必须和页面th标签数据量一致，否则会报错
            // orderable： 排序，默认为true
            "columns": [
            {
                "data": "headimgurl",
                "name": "headimgurl",
                "render": function ( data, type, row ) {
                		return "<img src='"+data+"' class='img-rounded' style = 'width: 60px;' />";
                }
            },
            {
                "data": "nickname",
                "name": "nickname",
            },
            {
                "data": "sex",
                "name": "sex",
                "render": function ( data, type, row ) {
                		if(data == 2){
                			return "女";
                		}else if(data == 1){
                			return "男";
                		}else{
                			return "未知";
                		}
                		return data;
                }
            },
            {
                "data": "language",
                "name": "language",
            },
            {
                "data": "country",
                "name" : "country",
            },
            {
                "data": "province",
                "name" : "province",
            },
            {
                "data": "city",
                "name" : "city",
            },
            {
              "data": "remark",
              "name": "remark",
            },
            {
                "data": "subscribe_time",
                "name" : "subscribe_time",
                "render":function(data){
                		var time = new Date(data*1000);
					var year = time.getFullYear();
					var month = time.getMonth()+1;
					var day = time.getDate();
					var hours = time.getHours();
					var minutes = time.getMinutes();
					var seconds = time.getSeconds();
					return year+'-'+formatData(month)+'-'+formatData(day)+' '+formatData(hours)+':'+formatData(minutes)+':'+formatData(seconds);
                }
            }
            ],
        });
	}
	var formatData = function(data){
		return data<10?'0'+data:data;
	}
	return {
        init : userInit
    }
}();
